function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

//格式化时间戳
function formatTimeFromTimestamp(timestamp) {
  var newDate = new Date();
  newDate.setTime(timestamp);
//
  var year = newDate.getFullYear()
  var month = newDate.getMonth() + 1
  var day = newDate.getDate()

  var hour = newDate.getHours()
  var minute = newDate.getMinutes()
  var second = newDate.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function clearEnterChar(inStr)
{
  var resultStr=inStr.replace(/[\r\n]/g,"");//去掉回车换行
  return resultStr;
}

module.exports = {
  formatTime: formatTime,
  formatTimeFromTimestamp:formatTimeFromTimestamp,
  clearEnterChar:clearEnterChar
}
